package com.itheima.threadsynchronizedfirst;


import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Account {
    private String cardId;
    private int money = 0;



    public void draw(int drawMoney){
        // 同步代码块
        synchronized (this){
            if(money >= drawMoney){
                System.out.println(Thread.currentThread().getName() + "取款中");
                // 模拟取款
                money -= drawMoney;
                System.out.println(Thread.currentThread().getName() + "取款成功，余额为：" + money);
            }else{
                System.out.println(Thread.currentThread().getName() + "取款失败，余额不足");
            }
        }
    }
}
